package com.sh.job.snailjob;

import cn.hutool.core.convert.Convert;
import com.aizuda.snailjob.client.job.core.annotation.JobExecutor;
import com.aizuda.snailjob.client.job.core.dto.JobArgs;
import com.aizuda.snailjob.client.model.ExecuteResult;
import com.aizuda.snailjob.common.core.util.JsonUtil;
import com.aizuda.snailjob.common.log.SnailJobLog;
import com.sh.business.domain.PriceTrends;
import com.sh.business.mapper.PriceTrendsMapper;
import com.sh.business.service.facade.TransactionServiceFacade;
import com.sh.business.service.facade.UserServiceFacade;
import com.sh.common.core.enums.UserFoundEnum;
import com.sh.common.core.utils.DateUtils;
import com.sh.system.service.ISysConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @author ruoyi
 * @date 2024-05-17
 */
@RequiredArgsConstructor
@Component
@JobExecutor(name = "dailySzpnPriceAnnoJobExecutor")
public class DailySzpnPriceAnnoJobExecutor {

    private final UserServiceFacade userServiceFacade;
    private final PriceTrendsMapper priceTrendsMapper;
    private final ISysConfigService iSysConfigService;
    private final TransactionServiceFacade transactionServiceFacade;

    public ExecuteResult jobExecute(JobArgs jobArgs) {
        SnailJobLog.LOCAL.info("DailyProduceAnnoJobExecutor. jobArgs:{}", JsonUtil.toJsonString(jobArgs));

        // 保存szpn价格
        PriceTrends szpnPriceTrends = new PriceTrends();
        szpnPriceTrends.setType(UserFoundEnum.AVAILABLE_SZPN.getCode());
        szpnPriceTrends.setPrice(Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.szpn.price")));
        szpnPriceTrends.setRealTime(DateUtils.getNowDate());
        priceTrendsMapper.insert(szpnPriceTrends);

        // 保存scroll价格
        PriceTrends scrollPriceTrends = new PriceTrends();
        scrollPriceTrends.setType(UserFoundEnum.SCR.getCode());
        scrollPriceTrends.setPrice(transactionServiceFacade.queryScrollPrice());
        scrollPriceTrends.setRealTime(DateUtils.getNowDate());
        priceTrendsMapper.insert(scrollPriceTrends);

        SnailJobLog.REMOTE.info("DailyProduceAnnoJobExecutor. jobArgs:{}", JsonUtil.toJsonString(jobArgs));
        return ExecuteResult.success("成功");
    }
}
